<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>密码邮箱修改</title>
	<link href="<%=basePath%>scripts/miniui/themes/blue/skin.css" rel="stylesheet" type="text/css" />
<script src="<%=basePath%>scripts/boot.js" type="text/javascript"></script> 
  </head>
  <body>
    <form action="" method="" class="main_form" >
    		<div align="center">
                <div class="text_info clearfix"><span>旧密码：</span></div>
                <div class="input_info" style="display: inline;">
                <input type="password" id="oldpassword" style="width:200px" >
                    <span class="required">*</span>
                </div>
                <div class="text_info clearfix"><span>修改内容：</span></div>
                <div class="input_info" style="display: inline;">
                 <select id="editmode" onchange="EditMode(this.value)" style="width: 100px">
                        <option value="1" selected="selected">密码</option>
                            <option value="2">邮箱</option>
                    </select>
                </div>
                <div id="editpaw">
                <div class="text_info clearfix" ><span>新密码：</span></div>
                <div class="input_info" style="display: inline;">
                <input type="password" id="newpassword" style="width:200px" >
                    <span class="required">*</span>
                </div>
                <div class="text_info clearfix"><span>重复新密码：</span></div>
                <div class="input_info" style="display: inline;">
                 <input type="password" id="newpassword2" style="width:200px" >
                    <span class="required">*</span>
                </div>
                </div>
                <div id="editemail" style="display: none;">
                <div class="text_info clearfix"><span>邮箱：</span></div>
                 <div class="input_info" style="display: inline;">
                 <input type="text" id="email" value="${user.email}" style="width:200px" >
                    <span class="required">*</span>
                </div>
                </div>
                <div class="button_info clearfix">
                <button type="button" class="btn btn-lg btn-alt m-r-5" onclick="showResult();" style="width: 100px;height: 30px">保存</button>
                </div>
                </div>
            </form>  
  </body>
  <script type="text/javascript">
  function getUrl(name) {
	    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	    var r = window.location.search.substr(1).match(reg);
	    if (r != null) return unescape(r[2]); return null;
	    }
	var editmode = getUrl("editmode");
	if(editmode!=null){
		if(editmode==2){
			EditMode(2);
			$("#editmode").val(2);
		}
	}
	
  function EditMode(num){
	  if(num==1){
		  $("#editemail").hide();
		  $("#editpaw").show();
	  }else{
		  $("#editpaw").hide();
		  $("#editemail").show();
	  }
  }
  function showResult(){
	  var editmode=$("#editmode").val();
      var oldpaw = $("#oldpassword").val();
      var newpaw = $("#newpassword").val();
      var newpaw2= $("#newpassword2").val();
      var email = $("#email").val().trim();
      if(oldpaw==""||oldpaw==null){
		alert("请输入旧密码！");
	  	return;
      }
      if(oldpaw.length>30){
	  	alert("旧密码长度不可超出30！");
	  	return;
      }
      if(editmode==1){
    	  if(newpaw==""||newpaw==null){
  			alert("请输入新密码！");
  		  	return;
  	}
        if(newpaw.length>30){
  			  	alert("新密码长度不可超出30！");
  			  	return;
  		}
        
        if(newpaw2==""||newpaw2==null){
  		alert("请重复新密码！");
  	  	return;
  }
        if(newpaw2.length>30){
  			  	alert("重复新密码长度不可超出30！");
  			  	return;
  		}
        if(newpaw!=newpaw2){
  	  	alert("新密码两次输入不一致");
  	  	return;
        }
        if(oldpaw==newpaw){
      	  alert("新密码与旧密码不可一致");
    	  	return;
        }
      }else{
    	  if(email==null||email==""){
    		  	alert("邮箱不可为空");
    		  	return;
    	      }
    	      var isemail = checkEmail(email);
    	      if(isemail==0){
    		  	alert("请输入有效的邮箱地址！");
    		  	return;
    	      }
      }
      mini.mask({
          el: document.body,
          cls: 'mini-mask-loading',
          html: '&nbsp;&nbsp;&nbsp;&nbsp;'
      });
      $.ajax({
		async : true,
		type : "post",
		url : "userset/EditPassword.do",
		data:{
			oldpaw:oldpaw,
			newpaw:newpaw,
			email:email,
			editmode:editmode
		},
		datatype: "json",
		success : function(data){
			mini.unmask(document.body);
				var list = eval("(" + data + ")");
				if(list.success=="success"){
				    alert("修改成功，建议您退出后重新登录");
				}
				if(list.success=="pawerror"){
				    alert("旧密码验证错误");
				}
				if(list.success=="no"){
					alert("ERR:修改失败!");
				}
			}
		}); 
      
  }
  function
  checkEmail(str){
     var
  re = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/
     if(re.test(str)){
         return 1;
     }else{
         return 0;
     }
 }
  </script>
</html>
